{template 'web/common/common'}
{template 'web/coupon/navbar'}
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<style>
    .upload{
        width: 500px;
        margin-bottom: 26px;
        margin-left: 60px;
    }
    .ibox-content{margin-top: 20px;}
</style>
<div class="panel panel-success">
    <div class="panel-heading">
        <h3 class="panel-title">
            兑换卡
        </h3>
    </div>
    <div class="ibox-content">
            <form class="form-horizontal" role="form"  action="{url 'site/entry/card',array('m'=>'kundian_farm','op'=>'card_index','version_id'=>$_GPC['version_id'])}"  method="post" enctype="multipart/form-data">
                <div class="form-group">
                    <label class="col-sm-1 control-label">卡号状态</label>
                    <div class="col-sm-3">
                        <select name="status" id="" class="form-control">
                            <option value="0">请选择</option>
                            <option value="3" <?php if($status==3){echo 'selected';}?> >未激活</option>
                            <option value="1" <?php if($status==1){echo 'selected';}?> >已激活</option>
                            <option value="2" <?php if($status==2){echo 'selected';}?> >已过期</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">卡号</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" name="card_num" value="{$card_num}" placeholder="卡号" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">UID</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" name="uid" value="{$uid}" placeholder="UID" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">昵称</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" name="nickname" value="{$nickname}" placeholder="昵称" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label"></label>
                    <div class="col-sm-8">
                        <button type="submit" class="btn btn-success">查询</button>
                    </div>
                </div>
            </form>
        <div class="upload">
            <form action="{url 'site/entry/card',array('m'=>'kundian_farm','op'=>'uploadExcel','version_id'=>$_GPC['version_id'])}" id="searchform" method="post" enctype="multipart/form-data">
                <div class="row" style="padding: 0 15px;">
                    <div class="col-sm-6">
                        <input type="file" class="form-control" name="upfile" />
                    </div>
                    <div class="col-sm-3">
                        <button type="submit" class="btn btn-info">导入兑换卡</button>
                    </div>
                    <div class="col-sm-2">
                        <a href="{$_W['siteroot']}addons/kundian_farm/resource/card_template.xls">
                            <button type="button" class="btn btn-info">下载模板</button></a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>



<div class="panel panel-success">

    <div class="panel-body">

        <form action="" method="post" class="form-horizontal form">
            <input type="hidden" name="token" value="{$_W['token']}">

            <div class="table-responsive panel-body">
                <table class="table-striped table-bordered table-hover dataTables-example table">
                    <thead class="navbar-inner">
                    <tr>
                        <th>ID</th>
                        <th>卡号</th>
                        <th>密码</th>
                        <th>导入时间</th>
                        <th>使用时间</th>
                        <th>过期时间</th>
                        <th>用户</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $list $index $item}
                    <tr>
                        <td><div class="type-parent">{$item['id']}</div></td>
                        <td><div class="type-parent">{$item['card_num']}</div></td>
                        <td><div class="type-parent">{$item['card_pwd']}</div></td>
                        <td><div class="type-parent">{$item['import_time']}</div></td>
                        <td><div class="type-parent">{$item['use_time']}</div></td>
                        <td><div class="type-parent">{$item['expire_time']}</div></td>
                        <td><div class="type-parent">{$item['nickname']}</div></td>
                        <td><div class="type-parent" style="width: 52px;height: 32px;">
                            {if $item['status']==0}
                            <span class="label label-default">未激活</span>
                            {else if $item['status']==1}
                            <span class="label label-success">已兑换</span>
                            {else if $item['status']==2}
                            <span class="label label-warning">已过期</span>
                            {/if}
                        </div></td>
                        <td>
                            {if $item['status']==0}
                            <a class="btn btn-danger btn-xs delete" data-id="{$item['id']}"><i class="fa fa-edit"></i>删除</a>
                            {else}
                            --
                            {/if}
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
                <div style="text-align: right;">
                    {$pager}
                </div>
            </div>
        </form>


    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function(){
            //删除
            $(".delete").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '确定删除吗?',
                    text: "确定删除吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'card_delete','version_id'=>$_GPC['version_id'])}",
                            data:{id:id},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    that.parent().parent().remove();
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });
        })
    })
</script>